package nc.bs.hrhi.bp;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import nc.jdbc.framework.processor.MapListProcessor;
import nc.vo.pub.BusinessException;
import nc.vo.pubapp.pattern.pub.SqlBuilder;

public class QueryLeaderBp extends AbsPubOp{
	
	public Map<String, Map<String, String>> exec(String[] pk_psndocs) throws BusinessException{
		
		SqlBuilder sqlB = new SqlBuilder();
		sqlB.append(" select  ");
		sqlB.append(" main.pk_psndoc as pk, main.code as code, main.name as name ");
		sqlB.append(" , lder.pk_psndoc as lderpk, lder.code as ldercode, lder.name as ldername ");
		sqlB.append(" , hrbp.pk_psndoc as hrbppk, hrbp.code as hrbpcode, hrbp.name as hrbpname ");
		sqlB.append(" from hi_psnjob  ");
		sqlB.append(" left join bd_psndoc main on main.pk_psndoc=hi_psnjob.pk_psndoc ");
		sqlB.append(" left join bd_psndoc lder on lder.pk_psndoc=hi_psnjob.jobglbdef1 ");
		sqlB.append(" left join bd_psndoc hrbp on hrbp.pk_psndoc=hi_psnjob.jobglbdef2 ");
		sqlB.append(" where hi_psnjob.lastflag='Y' and hi_psnjob.recordnum=0 and hi_psnjob.trnsevent <> 4 and main.pk_psndoc ", pk_psndocs);
		
		List<Map<String, String>> list = (List<Map<String, String>>) getDao().executeQuery(sqlB.toString(), new MapListProcessor());
		
		if(list != null && list.size() > 0) {
			Map<String, Map<String, String>> result = new HashMap<String, Map<String,String>>();
			for(Map<String, String> map : list) {
				result.put(map.get("pk"), map);
			}
			
			return result;
		}
		
		return null;
	}

}
